#!/usr/bin/env python3
#-*- coding:utf-8 -*-
import requests
from _bdtp import bdtp_storage

bdtp_base_url="https://image.baidu.com/search/acjson?tn=resultjson_com&logid=10647588102738471994&" \
              "ipn=rj&ct=201326592&is=&fp=result&queryWord={0}&cl=2&" \
              "lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=&copyright=&" \
              "word={1}&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&" \
              "expermode=&force=&pn={2}&rn={3}&gsm=78&1602481927094="

bdtp_page_count=4
page_size=30
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0"
}

def bdtp_images(keyword):
    iamges =[]
    urls=[bdtp_base_url.format(keyword,keyword,(i * page_size),page_size)
          for i in range(1,bdtp_page_count)]
    for url in urls:
        r=requests.get(url,headers=headers)
        r.encoding=r.apparent_encoding
        results=r.json().get("data")
        for result in results:
            iamges.append(result.get("middleURL"))
    print(iamges)
    return iamges

if __name__ == '__main__':
    keywords="周震南"
    bdtp_storage.storage_local(keywords, bdtp_images(keywords))